package com.loongtech.core.util;

import com.fasterxml.jackson.core.JsonProcessingException;

import java.util.LinkedHashMap;
import java.util.Map;

public enum RetCode {
    eRedisEmtity(-1, "redis数据过期"),
    eSuccess(0, "操作成功"),
    eOtherException(30000, "失败,数据库操作异常"),
    eFatherEmpty(30001, "增加失败,父模块为空"),
    eNameExist(30002, "操作失败,名称已存在或未做修改"),
    eIdExist(30003, "操作失败,id已存在"),
    eRelationExist(30004, "操作失败,模块下有关联模块"),
    eModuleEmpty(30005, "操作失败,无此模块"),
    eFunctionEmpty(30006, "操作失败,无此功能页面"),
    eSelfErrorCommit(30007, "操作失败,自己不能删除自己或重置密码"),
    eAdminErrorCommit(30008, "操作失败,管理员不能被删除或重置密码"),
    ePasswordFormatError(30009, "操作失败,密码格式错误"),
    eFunctionOrRoleEmpty(30010, "操作失败,无此角色或功能页面"),
    eEmptyUserNameError(30011, "操作失败,名称不能为空"),
    eEmptyWeChatError(30012, "操作失败,微信号不能为空"),
    eEmptyPhoneNumError(30013, "操作失败,手机号不能为空"),
    eEmptyVoiceNumError(30014, "操作失败,语音号不能为空"),
    eEmptyEmailError(30015, "操作失败,邮箱不能为空"),
    eEmptyVoiceTemplateError(30016, "语音号已勾选，不能为空"),
    eGroupBelongToMonitor(30017, "操作失败,分组有所属监控"),
    eGroupHasUser(30018, "操作失败,分组下有用户"),
    eNotExistUser(30019, "操作失败,用户id不存在"),
    eNotExistName(30020, "操作失败,名称不能为空"),
    eEmptyId(30021, "操作失败,id不能为空"),
    eNotExistGourp(30022, "操作失败,此id不存在"),
    eEmptyQuery(30023, "操作失败,查询语句不能为空"),
    eEmptyThresh(30024, "操作失败,阀值不能为空"),
    eMinusValueMonitorTime(30025, "操作失败,监控次数需要大于0"),
    eNotExistGroupId(30026, "操作失败,监控组别不能为空"),
    eIlegalInterval(30027, "操作失败,监控频率大于0且不能为空"),
    eIlegalTime(30028, "操作失败,日期不为空且开始时间小于结束时间"),
    eEmptyPassWord(30029, "操作失败,密码不能为空"),
    eErrPassWordUserName(30030, "操作失败,用户名或密码错误"),
    eNotAllowOperation(30031, "操作失败,不允许修改类操作"),
    eEmptySerGroup(30032, "操作失败,区服分组不能为空"),
    eEmptySerChannel(30033, "操作失败,区服渠道不能为空"),
    eEmptyChannelPlat(30034, "操作失败,渠道所属平台不能为空"),
    eRChannelServer(30035, "操作失败,此渠道与区服有关联"),
    eRPlatChannel(30036, "操作失败,此平台与渠道有关联"),
    eRChannelFuction(30037, "操作失败,此渠道已被分配到页面过滤"),
    eEmptyParamType(30038, "操作失败,参数类型不能为空"),
    eEmptyParamValue(30039, "操作失败,参数值不能为空"),
    eIDorNameExist(30040, "操作失败,ID或名称重复"),
    eEmptyDate(30041, "操作失败,日期不能为空"),
    eEmptyChanPlat(30042, "操作失败,渠道平台不能为空"),
    eEmptyAgent(30043, "操作失败,代理公司不能为空"),
    eEmptyChanName(30044, "操作失败,渠道名称不能为空"),
    eEmptyCost(30045, "操作失败,成本不能为空"),
    eEmptyProfit(30046, "操作失败,返点不能为空"),
    eEmptyBelong(30047, "操作失败,归属不能为空"),
    eEmptyActiveName(30048, "操作失败,活动名称"),
    eEmptySettlement(30049, "操作失败,结算方式不能为空"),
    eEmptyAdvPlace(30050, "操作失败,广告位置不能为空"),
    eEmptyDisCountCost(30051, "操作失败,折后成本不能为空"),
    eEmptyProfitShare(30052, "操作失败,分成比例不能为空"),
    eEmptyUploadFile(30052, "操作失败,上传文件为空"),
    eIOUploadFile(30053, "操作失败,上传文件IO错误"),
    eParseExcel(30054, "操作失败,Excel表内容为空或解析错误"),
    eFileTypeIncomform(30055, "操作失败,参数类型与文件中类型不一致"),
    eEmptyGameId(30056, "操作失败,游戏id不能为空"),
    eEmptyGameName(30057, "操作失败,游戏名称不能为空"),
    eEmptyProject(30058, "操作失败,无此项目!"),
    NOTLOGIN(99999, "未登录");




    private final int errorcode;
    private String errorMsg;

    RetCode(int errorcode, String errorMsg) {
        this.errorcode = errorcode;
        this.errorMsg = errorMsg;
    }

    public int getErrorcode() {
        return errorcode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public static RetCode getEnumById(int id) {
        for (RetCode info : RetCode.values()) {
            if (info.getErrorcode() == id) {
                return info;
            }
        }
        return null;
    }

    public static Map<Integer, String> getCodeMap() {
        Map<Integer, String> map = new LinkedHashMap<>();
        for (RetCode info : RetCode.values()) {
            map.put(info.getErrorcode(), info.getErrorMsg());
        }
        return map;
    }

    public static Map<Integer, String> retCodeToMap(RetCode retCode) {
        Map<Integer, String> map = new LinkedHashMap<>();
        map.put(retCode.getErrorcode(), retCode.getErrorMsg());
        return map;
    }

    public static void main(String[] args) throws JsonProcessingException {
//        String json = retCodeToMap(RetCode.eIdExist);
//        System.out.println(json);
    }
}
